/**
 * 添加 编辑车道
 * @author xiaoxujs
 */

import { Form, Input, message, Modal } from "antd";
import { FC } from "react";
import { IBaseLaneListAddForm } from "../../../../type/chedaoweihu";
import { postBaseLaneAdd } from "../../api";

const ChedaoAddChangeModule: FC<{
  open: boolean;
  handleCallback: () => void;
}> = ({
  open,
  handleCallback
}) => {
    const [form] = Form.useForm();
    const { validateFields, resetFields } = form;
    const handleOk = async () => {
      const values = await validateFields();
      const { code, msg } = await postBaseLaneAdd(values) as { code: number, msg: string };
      if (code === 20000) {
        resetFields()
        handleCallback();
      } else {
        message.error(msg)
      }
    };

    const handleCancel = () => {
      resetFields()
      handleCallback()
    };
    return <Modal title='添加车道' open={open} onOk={handleOk} onCancel={handleCancel}>
      <Form
        labelCol={{ span: 6 }}
        wrapperCol={{ span: 16 }}
        form={form}
      >
        <Form.Item<IBaseLaneListAddForm>
          label="车道ID"
          name="laneId"
          rules={[{ required: true, message: ' 请输入车道ID!' }]}
        >
          <Input />
        </Form.Item>
        <Form.Item<IBaseLaneListAddForm>
          label="车道名称"
          name="laneName"
          rules={[{ required: true, message: '请输入车道名称!' }]}
        >
          <Input />
        </Form.Item>
      </Form>
    </Modal>
  }

export default ChedaoAddChangeModule;